Sys.Application.add_init(appInit);

function appInit(sender, initEventArgs) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_initializeRequest(InitializeRequest);
    prm.add_beginRequest(BeginRequest);
    prm.add_pageLoading(PageLoading);
    prm.add_pageLoaded(PageLoaded);
    prm.add_endRequest(EndRequest);
}

function InitializeRequest(sender, initializeRequestEventArgs) {
    alert('In Initialize Request');
}

function BeginRequest(sender, beginRequestEventArgs) {
    alert('In Begin Request');
}

function PageLoading(sender, pageLoadingEventArgs) {
    alert('In Page Loading');
}

function PageLoaded(sender, pageLoadedEventArgs) {
    var returnedContent = pageLoadedEventArgs._panelsUpdated[0].innerHTML; 
    var navs = eval('(' + returnedContent + ')').Nav;   
    if(navs) {

        var sbContent = new Sys.StringBuilder("<ul>");
        var lineItemFormat = "<li><a href=\"{0}\">{1}</a></li>";
        var lineItem = new String();

        for(var r=0; r<navs.length; r++) {
            lineItem = String.format( lineItemFormat, 
                       navs[r].Url, 
                       navs[r].Name );
            sbContent.append( lineItem );
        }   
        sbContent.append( "</ul>" );
        
        pageLoadedEventArgs._panelsUpdated[0].innerHTML = sbContent.toString();
    }   
}

function EndRequest(sender, endRequestEventArgs) {
    //Do Nothing, just for Demo
}
